<?php

declare(strict_types=1);

namespace app\store\controller\tools;

use app\store\controller\Controller;
use think\App;
use think\response\Json;
use app\store\service\tools\Recharge as ChargeService;

class Recharge extends Controller
{

    private $chargeService;
    public function __construct(App $app,ChargeService $chargeService)
    {
        parent::__construct($app);
        $this->chargeService = $chargeService;
    }

    //列表
    public function list():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                'check_status' => 'integer',
                'page' => 'integer',
                'limit' => 'integer'
            ]
        );
        $list = $this->chargeService->getList($params);
        return $this->renderSuccess(compact('list'));
    }

    public function check():Json
    {
        $params = $this->request->post();
        $this->validate(
            $params,
            [
                'id' => 'require|integer',
                'type' => 'require|integer',    //1 审核通过  -1拒绝
            ]
        );
        if(!in_array($params['type'],[-1,1])){
            return $this->renderError('参数错误');
        }
        $res = $this->chargeService->check($params);
        if(!$res){
            return $this->renderError('审核异常');
        }
        return $this->renderSuccess('审核成功');
    }

    public function delete():Json
    {
        $params = $this->request->get();
        $this->validate(
            $params,
            [
                'id' => 'require|integer',
            ]
        );
        $id = $params['id'];
        $res = $this->chargeService->delete($id);
        if(!$res){
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }





}